package study;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class jsoup {
    public static void main(String[] args) {
        jsoup jsoup = new jsoup();
//        System.out.println(jsoup.jsopget1("http://www.baidu.com"));
//        System.out.println(jsoup.jsopget2("http://www.baidu.com/s", "loadrunner"));
//        Document doc = jsoup.jsoppost("http://localhost/defect/login.php","password");
//
//        if(doc.toString().contains("fail")){
//            System.out.println("pass");
//        }else {
//            System.out.println("fail");
//        }
//        Document doc = jsoup.jsopget1("http://www.baidu.com");
//        Elements element = doc.select(".lb");
//        System.out.println(element.get(0).toString());
//        System.out.println(element.get(0).ownText());
//        System.out.println(jsoup.jsoppost("http://localhost/defect/login.php","password"));
        System.out.println(System.getProperty("java.library.path"));
    }


    public Document jsopget1(String url) {
        Document doc;
        try {
            doc = Jsoup.connect(url).get();
            return doc;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public Document jsopget2(String url, String param) {
        Document doc;
        try {
            Connection conn = Jsoup.connect(url);
            conn.data("wd", param);
            doc = conn.get();
            return doc;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public Document jsoppost(String url, String param) {
        Document doc;
        try {
            Connection conn = Jsoup.connect(url);
            conn.data("username", "cloud");
            conn.data("password", param);
            doc = conn.post();
            return doc;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
